package
        com.zzc.sale.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hos.entity.stock.InventoryLog;
import com.hos.entity.stock.Medicines;
import com.zzc.sale.mapper.InventoryLogMapper;
import com.zzc.sale.service.InventoryLogService;
import com.zzc.sale.vo.InventoryLogVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author：xIAO_ZHOU_TX
 * @date：Created in 2023/12/18 10:24
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class InventoryLogServiceImpl implements InventoryLogService {
    @Resource
    private InventoryLogMapper inventoryLogMapper;
    @Override
    public Page<InventoryLog> listInventoryLogForPage(InventoryLogVo inventoryLogVo) {
        Page<InventoryLog> page =new Page<>(inventoryLogVo.getPageNum(),inventoryLogVo.getPageSize());
        LambdaQueryWrapper<InventoryLog> wrapper =new LambdaQueryWrapper<>();
        //采购单据号
        if(StringUtils.hasText(inventoryLogVo.getPurchaseId())){
            wrapper.eq(InventoryLog::getPurchaseId,inventoryLogVo.getPurchaseId());
        }
        //药品名称
        if(StringUtils.hasText(inventoryLogVo.getMedicinesName())){
            wrapper.like(InventoryLog::getMedicinesName,inventoryLogVo.getMedicinesName());
        }
        //药品类型
        if(StringUtils.hasText(inventoryLogVo.getMedicinesType())){
            wrapper.eq(InventoryLog::getMedicinesType,inventoryLogVo.getMedicinesType());
        }
        //生产厂家
        if(StringUtils.hasText(inventoryLogVo.getProducterId())){
            wrapper.eq(InventoryLog::getProducterId,inventoryLogVo.getProducterId());
        }
        //处方类型
        if(StringUtils.hasText(inventoryLogVo.getPrescriptionType())){
            wrapper.eq(InventoryLog::getPrescriptionType,inventoryLogVo.getPrescriptionType());
        }
        //创建时间
        if (Objects.nonNull(inventoryLogVo.getDateRange())) {
            wrapper.between(InventoryLog::getCreateTime, inventoryLogVo.getDateRange()[0], inventoryLogVo.getDateRange()[1]);
        }
        return inventoryLogMapper.selectPage(page,wrapper);
    }
}